package com.example.shop.controller;

import com.example.shop.entity.Role;
import com.example.shop.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName RoleController
 * @Description TODO
 * @Author 吴
 * @Date 2025/3/26 10:22
 */
@RestController
@RequestMapping("role")
public class RoleController {
    /**
     * 服务对象
     */
    @Autowired
    private RoleService roleService;

    /**
     * 通过ID查询单条数据
     *
     * @param roleid 主键
     * @return 单条数据
     */
    @GetMapping("{roleid}")
    public Role queryById(@PathVariable("roleid") Integer roleid) {
        return roleService.queryById(roleid);
    }

    /**
     * 新增数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @PostMapping
    public Role insert(@RequestBody Role role) {
        return roleService.insert(role);
    }

    /**
     * 修改数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @PutMapping
    public Role update(@RequestBody Role role) {
        return roleService.update(role);
    }

    /**
     * 通过主键删除数据
     *
     * @param roleid 主键
     * @return 是否成功
     */
    @DeleteMapping("{roleid}")
    public boolean deleteById(@PathVariable("roleid") Integer roleid) {
        return roleService.deleteById(roleid);
    }
}
